package com.five.taotao.guide_mine;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;

import com.five.taotao.Adapter.GoodsCollectAdapter;
import com.five.taotao.Application.MyApplication;
import com.five.taotao.R;
import com.five.taotao.dao.ProductListBeanDao;
import com.five.taotao.entity.Product;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * gaomengjiao
 * A simple {@link Fragment} subclass.
 */
public class GoodsCollectFragment extends Fragment {
    @BindView(R.id.rv)
    RecyclerView rv;

    private List<Product.ListBean> mData;
    private ProductListBeanDao dao;
    private GoodsCollectAdapter adapter;

    public GoodsCollectFragment() {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_goods_collect, container, false);
        ButterKnife.bind(this, view);
        mData = new ArrayList<>();
        dao = new ProductListBeanDao(getActivity());
        adapter = new GoodsCollectAdapter(getActivity(), mData);
        //设置布局管理器，必须要有
        rv.setLayoutManager(new LinearLayoutManager(getActivity()));
        //设置Item增加、移除动画
        rv.setItemAnimator(new DefaultItemAnimator());
        rv.setAdapter(adapter);

        initData();

        rv.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
            @Override
            public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
                return false;
            }

            @Override
            public void onTouchEvent(RecyclerView rv, MotionEvent e) {

            }

            @Override
            public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {

            }
        });

        return view;
    }

    /**
     * 初始化数据，   此处为假数据测试
     */
    private void initData() {
        mData.addAll(dao.findProductByCollected(1));
        adapter.notifyDataSetChanged();

    }

}
